package com.wang.madness.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.Getter;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 获取当前request/response
 * @author DanielWu
 */
@Getter
public class GetRequestAndResponse {

  private final HttpServletRequest httpServletRequest;

  private final HttpServletResponse httpServletResponse;

  public GetRequestAndResponse () {
    ServletRequestAttributes currentRequestAttributes = (ServletRequestAttributes) RequestContextHolder
        .currentRequestAttributes();
    this.httpServletRequest = currentRequestAttributes.getRequest();
    this.httpServletResponse = currentRequestAttributes.getResponse();
  }

}
